<?php include dirname(__FILE__).'/common/header.php'; ?>

<?php include dirname(__FILE__).'/common/menu.php'; ?>

var ctrlName = '<?php echo $ctrlName ?>';
var attr = {};
attr.news_image_width = <?php echo $attr['news_image_width']; ?>;
attr.news_image_height = <?php echo $attr['news_image_height']; ?>;

list.baseFrm = function(r){
    var paramsData = r ? {news_id:r.news_id}: {};
    var win = new ZM.PopUp({
        title:r ? '编辑新闻:' + r.news_title : '新建新闻',
        type:'l',
        items:new ZM.FormPanel({
            url:list.baseUrl +  ctrlName + (r ? '/editnews' : '/createNews'),
            keySubmit:false,
            fileUpload:true,
            params:paramsData,
            //onlyShow:r ? r.news_status == 1 : false,
            keySubmit:false,
    				defaults:{xtype:'textfield',width:800},
            success:function(res) {
                ZM.bo.msg('success',res.detail);
                list.grid.store.reload();
                win.close();
            },
            items:[{
                fieldLabel:'标题',
                name:'news_title',
                value: r ? r.news_title : '',
                allowBlank:false
            },{
                xtype:'textarea',
                fieldLabel:'简介',
                name:'news_desc',
                value: r ? r.news_desc : '',
                maxLength: 230,
                allowBlank:false
            },{
                xtype:'displayfield',
                fieldLabel:'现有图片',
                value:r ? ZM.cellImage(r.news_image) : '',
                hidden:r ? false : true
            },{
                inputType:'file',
                fieldLabel:'图片',
                name:'news_image',
                allowBlank:r ? true : false
            },{
                xtype:'displayfield',
                fieldLabel:'',
                value:'<span class="red">上传图片大小:'+attr.news_image_width+'x'+attr.news_image_height+'</span>'
            },{
              xtype: 'editor',
    					fieldLabel:'详情',
    					name: 'news_content',
              value: r ? r.news_content : '',
    					allowBlank:false,
    					uploadUrl:'app/addImage',
    					maxLength: 500000
            }]
        })
    }).show();
}


list.statusFrm = function(r,msg,method){
    Ext.Msg.confirm('确认?',msg,function(btn) {
        if(btn != 'no') {
            ZM.ajax({
                url: list.baseUrl +  ctrlName + method,
                params:{news_id:r.news_id},
                mask:list.grid,
                success:function(res){
                    ZM.bo.msg('success!',res.detail);
                    list.grid.store.reload();
                }
            });
        }
    });
}

/*
| -------------------------------------------------------------------
|  List Grid
| -------------------------------------------------------------------
*/
list.grid = new ZM.EditorGridPanel({
	tbar:[{
		text:'新建新闻',
		cls:'btn-show',
		hidden:!Ext.permission['news/createNews'.toLowerCase()],
		iconCls:'icon-create',
		handler:function() {
			list.baseFrm(false);
		}
	}],
	url: list.baseUrl + 'news/getNewsList',
	autoExpandColumn:'aeColumn',
	columns:[
		{header:'ID',dataIndex:'news_id'},
    {header:'标题',dataIndex:'news_title',filter:{}},
		{header:'图片',dataIndex:'news_image',renderer:ZM.cellImage},
		{header:'简介',dataIndex:'news_desc',id:'aeColumn'},
		//{header:'点击次数',dataIndex:'news_hits',id:'aeColumn'},
		//{header:'分享内容',dataIndex:'news_sharecontent',width:200},
		{header:'推荐首页',dataIndex:'news_flg_home',width:65,renderer:ZM.status},
		{header: "排序",xtype:'sortcolumn',url: 'news/editNewsSort',dataId:'news_id',dataIndex: 'news_sort'},
		{header:'状态',dataIndex:'news_status',width:65,renderer:ZM.status},
		//{header:'最后修改人',dataIndex:'user_name',width:75},
		{header:'最后修改时间',dataIndex:'news_time_lastmodified',width:85},
		{header:'操作',width:150,renderer:function(v,p,r){
			var str = '';
			str += Ext.rd('编辑','fireEdit',r,'news/editNews');
			if(r.json.news_flg_home != '1') {
				str += Ext.rd('推荐首页','fireHome',r,'news/homeNews','green');
			}
			if(r.json.news_status == '1') {
				str += Ext.rd('取消发布','fireDisable',r,'news/disableNews','red');
			} else {
				str += Ext.rd('发布','fireActive',r,'news/activeNews','green');
        str += Ext.rd('删除','fireDelete',r,'news/deleteNews','red');
			}
			return str;
		}}
	]
});



list.grid.fireEdit = function(r) {
    var r = r.json;
    list.baseFrm(r);
}

list.grid.fireDisable = function(r) {
    var r = r.json;
    list.statusFrm(r,'确定要禁用新闻['+r.news_title+']?','/disableNews');
}

list.grid.fireActive = function(r) {
    var r = r.json;
    list.statusFrm(r,'确定要发布新闻['+r.news_title+']?','/activeNews');
}
list.grid.fireDelete = function(r) {
    var r = r.json;
    list.statusFrm(r,'确定要删除新闻['+r.news_title+']?','/deleteNews');
}
list.grid.fireHome = function(r) {
    var r = r.json;
    list.statusFrm(r,'确定要推荐首页新闻['+r.news_title+']?','/homeNews');
}



<?php include dirname(__FILE__).'/common/layout.php'; ?>
list.grid.store.load();
<?php $includeEditor = true ?>
<?php include dirname(__FILE__).'/common/footer.php'; ?>
